package com.autoglm.android.core.models

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

/**
 * 执行步骤，表示任务执行计划中的一个步骤
 */
data class ExecutionStep(
    @SerializedName("id") val id: String,
    @SerializedName("description") val description: String,
    @SerializedName("actionType") val actionType: ActionType,
    @SerializedName("targetElement") val targetElement: String? = null,
    @SerializedName("params") val params: Map<String, Any>? = null,
    @SerializedName("successCriteria") val successCriteria: String? = null,
    @SerializedName("timeoutMs") val timeoutMs: Long? = null,
    @SerializedName("fallbackSteps") val fallbackSteps: List<String> = emptyList()
) {
    /**
     * 动作类型
     */
    enum class ActionType {
        @SerializedName("APP_LAUNCH") APP_LAUNCH,       // 启动应用
        @SerializedName("CLICK") CLICK,                 // 点击元素
        @SerializedName("SWIPE") SWIPE,                 // 滑动屏幕
        @SerializedName("ENTER_TEXT") ENTER_TEXT,       // 输入文本
        @SerializedName("WAIT") WAIT,                   // 等待
        @SerializedName("SCREENSHOT") SCREENSHOT,       // 截图
        @SerializedName("CHECK_ELEMENT") CHECK_ELEMENT, // 检查元素
        @SerializedName("BACK") BACK,                   // 返回
        @SerializedName("HOME") HOME,                   // 回到主屏幕
        @SerializedName("CUSTOM") CUSTOM                // 自定义操作
    }
    
    /**
     * 转换为JSON字符串
     */
    fun toJson(): String {
        return Gson().toJson(this)
    }
    
    companion object {
        /**
         * 从JSON字符串解析
         */
        fun fromJson(json: String): ExecutionStep {
            return Gson().fromJson(json, ExecutionStep::class.java)
        }
    }
}

/**
 * UI元素标识符，用于在界面中查找特定元素
 */
data class UIElementIdentifier(
    @SerializedName("text")
    val text: String? = null,
    
    @SerializedName("contentDescription")
    val contentDescription: String? = null,
    
    @SerializedName("resourceId")
    val resourceId: String? = null,
    
    @SerializedName("className")
    val className: String? = null,
    
    @SerializedName("container")
    val container: String? = null,
    
    @SerializedName("childIndex")
    val childIndex: Int? = null
) 